package com.pv.bfc.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.pv.bfc.dao.FolderRepository;
import com.pv.bfc.model.Folder;

public class DeleteFolderController extends AbstractController {

	private static final String FOLDER_VIEW = "redirect:folders.htm";

	public DeleteFolderController() {
	}

	private static final Log logger = LogFactory
			.getLog(DeleteFolderController.class);

	private FolderRepository folderRepo;

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		logger.info("IN DeleteFolderController - deleteFolder");

		logger.info("Getting Folder information for FolderID -"
				+ request.getParameter("folderID"));
		Folder folderToDelete = folderRepo.retrieveFolderById(Integer
				.parseInt(request.getParameter("folderID")));

		logger.info("Delteing Folder....");
		folderRepo.deleteFolder(folderToDelete);

		logger.info("OUT DeleteFolderController - deleteFolder");
		ModelAndView mav = new ModelAndView(FOLDER_VIEW);
		return mav;
	}

	public void setFolderRepo(FolderRepository folderRepo) {
		this.folderRepo = folderRepo;
	}

}
